//2190.数组中紧跟 key 之后出现最频繁的数字
//https://leetcode.cn/problems/most-frequent-number-following-key-in-an-array/
class Solution {
public:
    int mostFrequent(vector<int>& nums, int key) {
        unordered_map<int,int> hash;
        int cnt = 0;
        int ret = 0;
        int n = nums.size();

        for(int i = 0;i<n;++i)
        {
            if(nums[i] == key && i+1<n) 
            {
                ++hash[nums[i+1]];
                if(hash[nums[i+1]] > cnt)
                {
                    cnt = hash[nums[i+1]];
                    ret = nums[i+1];
                }
            }
            
        }
        
        return ret;
    }
};